package com.duobaoyu.dby.supply.admin.controller.message;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.duobaoyu.dby.channel.adapter.enums.OperationTypeEnum;
import com.duobaoyu.dby.common.core.util.R;
import com.duobaoyu.dby.supply.admin.annotation.SupplySysLog;
import com.duobaoyu.dby.supply.admin.converter.SupplyChainAdminConverter;
import com.duobaoyu.dby.supply.biz.service.message.MessageService;
import com.duobaoyu.dby.supply.common.biz.dto.message.MqMessageDTO;
import com.duobaoyu.dby.supply.common.biz.vo.message.MqMessageVO;
import com.duobaoyu.dby.supply.db.entity.message.MqMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * Mq消息管理
 * @author liyang
 * @version 1.0.0
 * @ClassName SystemLogController
 * @createTime 13:38:00 2023/04/21
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/mq-message")
@Api(value = "mq-message", tags = "mq消息")
public class MqMessageController {

	private final SupplyChainAdminConverter supplyChainAdminConverter;
	private final MessageService messageService;

	/**
	 * 分页查询mq信息
	 *
	 * @param mqMessage
	 * @return
	 */
	@PostMapping("/page")
	@ApiOperation(value = "分页查询mq信息", notes = "分页查询mq信息")
	@SupplySysLog(value = "分页查询mq信息",operationType = OperationTypeEnum.SELECT)
	public R<Page<MqMessageVO>> page(@RequestBody MqMessageDTO mqMessage) {
		Page<MqMessage> mqMessagePage = messageService.mqMessagePage(mqMessage);
		return R.ok(supplyChainAdminConverter.toMqMessagePage(mqMessagePage));
	}

	/**
	 * 重试按钮
	 *
	 * @param id id
	 * @return Boolean
	 */
	@GetMapping("/retry/{id}")
	@ApiOperation(value = "RocketMQ消息重试", notes = "RocketMQ消息重试")
	@SupplySysLog(value = "RocketMQ消息重试",operationType = OperationTypeEnum.UPDATE)
	public R<Boolean> retry(@PathVariable("id") String id) {
		boolean result = messageService.retryRocketMqMessage(id,null);
		return result ? R.ok(Boolean.TRUE) : R.failed("消息重试失败");
	}
}
